home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 008a / umbmem.zip / TESTUMB.C < prev    next >
C/C++ Source or Header  |  1991-07-07  |  3KB  |  99 lines

  1. #include <assert.h>
  2. #include <stdio.h>
  3. #include <dos.h>
  4. #include <memory.h>
  5. #include "umbhelp.h"
  6.  
  7. void AllocateLarge(void);
  8. void AllocateBlock(unsigned);
  9. void AllocateOffset(unsigned);
  10.  
  11. main(int argc, char *argv[])
  12. {
  13.     unsigned int uSize, uHandle, ArgSize = 0;
  14.     if (argc > 1)
  15.         ArgSize = atoi(argv[1]);
  16.     if (ArgSize == 0)
  17.         ArgSize = 512;
  18.     assert(umb_init() == 0);
  19.     assert(umb_allocate(-1, &uHandle, &uSize) == 0xb0);
  20.     printf("Largest free block 0x%04X Paragraphs\n", uSize);
  21.     assert(umb_allocate(uSize, &uHandle, &uSize) == 0);
  22.     printf("Allocated Handle = 0x%04X, size = 0x%04X\n", uHandle, uSize);
  23.     assert(umb_free(uHandle) == 0);
  24.     AllocateLarge();
  25.     AllocateBlock(ArgSize);
  26.     AllocateOffset(ArgSize);
  27.     AllocateLarge();
  28.     return(0);
  29. }
  30.  
  31. void AllocateLarge(void)
  32. {
  33.     unsigned uSizeTbl[256];
  34.     unsigned uHandleTbl[256];
  35.     int i, n;
  36.     printf("\nAllocate All of Upper Memory\n");
  37.     for (i = 0; i < 256; i++) {
  38.         if (umb_allocate(-1, &uHandleTbl[i], &uSizeTbl[i]) != 0xb0)
  39.         break;
  40.         assert(umb_allocate(uSizeTbl[i], &uHandleTbl[i], &uSizeTbl[i]) == 0);
  41.         printf("Allocate %3i, Handle = 0x%04X Size = 0x%04X\n", i, uHandleTbl[i], uSizeTbl[i]);
  42.     }
  43.     n = i;
  44.     for (i = 0; i < n; i++) {
  45.         assert(umb_free(uHandleTbl[i]) == 0);
  46.         printf("Free     %3i, Handle = 0x%04X\n", i, uHandleTbl[i]);
  47.     }
  48. }
  49.  
  50. void AllocateBlock(unsigned uSize)
  51. {
  52.     unsigned uSizeTbl[256];
  53.     unsigned uHandleTbl[256];
  54.     int i, n;
  55.     void far * dest;
  56.     printf("\nAllocate 0x%04X Blocks\n", uSize);
  57.     for (i = 0; i < 256; i++) {
  58.         if (umb_allocate(uSize, &uHandleTbl[i], &uSizeTbl[i]) != 0) {
  59.         printf("Largest block left = 0x%04X\n", uSizeTbl[i]);
  60.         break;
  61.         }
  62.         printf("Allocate %3i, Handle = 0x%04X Size = 0x%04X\n", i, uHandleTbl[i], uSizeTbl[i]);
  63.         FP_OFF(dest) = 0;
  64.         FP_SEG(dest) = uHandleTbl[i];
  65.         _fmemset(dest, 0x5a, uSizeTbl[i] * 16);
  66.     }
  67.     AllocateLarge();
  68.     n = i;
  69.     for (i = 0; i < n; i++) {
  70.         assert(umb_free(uHandleTbl[i]) == 0);
  71.         printf("Free     %3i, Handle = 0x%04X\n", i, uHandleTbl[i]);
  72.     }
  73. }
  74.  
  75. void AllocateOffset(unsigned uSize)
  76. {
  77.     unsigned uSizeTbl[256];
  78.     unsigned uHandleTbl[256];
  79.     int i, n;
  80.     printf("\nAllocate 0x%04X Blocks\n", uSize);
  81.     for (i = 0; i < 256; i++) {
  82.         if (umb_allocate(uSize, &uHandleTbl[i], &uSizeTbl[i]) != 0) {
  83.         printf("Largest block left = 0x%04X\n", uSizeTbl[i]);
  84.         break;
  85.         }
  86.         printf("Allocate %3i, Handle = 0x%04X Size = 0x%04X\n", i, uHandleTbl[i], uSizeTbl[i]);
  87.     }
  88.     n = i;
  89.     AllocateLarge();
  90.     for (i = 0; i < n; i += 2) {
  91.         assert(umb_free(uHandleTbl[i]) == 0);
  92.         printf("Free     %3i, Handle = 0x%04X\n", i, uHandleTbl[i]);
  93.     }
  94.     for (i = 1; i < n; i += 2) {
  95.         assert(umb_free(uHandleTbl[i]) == 0);
  96.         printf("Free     %3i, Handle = 0x%04X\n", i, uHandleTbl[i]);
  97.     }
  98. }
  99.